/**
 * 
 */
package info.niwota.fwrite;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

/**
 * @author qiangli
 *
 */
public class StatusHelper {
	private static final int SERVICE_ID = R.string.application_name;

	private static final int INBOX_SERVICE_ID = R.string.application_inbox; 
	
	private StatusHelper() {
	}

	static void addIncomingNotification(Context ctx, String ticker) {
		try {
			Notification note = new Notification(R.drawable.alert22, ticker, 0);
			PendingIntent pi = PendingIntent.getActivity(ctx, 0, new Intent(
					ctx, IncomingMessageActivity.class), 0);
			note.flags |= Notification.FLAG_AUTO_CANCEL;
			
			note.defaults |= Preferences.getNotifications(ctx);
			//
			CharSequence title = ctx.getText(R.string.application_name);
			CharSequence desc = ctx.getText(R.string.application_inbox);
			note.setLatestEventInfo(ctx, title, desc, pi);
			NotificationManager nm = (NotificationManager) ctx
					.getSystemService(Context.NOTIFICATION_SERVICE);
			nm.notify(INBOX_SERVICE_ID, note);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static void removeIncombingNotification(Context ctx) {
		try {
			NotificationManager nm = (NotificationManager) ctx
					.getSystemService(Context.NOTIFICATION_SERVICE);
			//
			nm.cancel(INBOX_SERVICE_ID);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static void addNotification(Context ctx) {
		try {
			Notification note = new Notification(R.drawable.frite22, null, 0);
			PendingIntent pi = PendingIntent.getActivity(ctx, 0, new Intent(
					ctx, WriteActivity.class), 0);
			note.flags |= Notification.FLAG_NO_CLEAR;
			note.flags |= Notification.FLAG_ONGOING_EVENT;
			//
			CharSequence title = ctx.getText(R.string.application_name);
			CharSequence desc = ctx.getText(R.string.application_desc);
			note.setLatestEventInfo(ctx, title, desc, pi);
			NotificationManager nm = (NotificationManager) ctx
					.getSystemService(Context.NOTIFICATION_SERVICE);
			nm.notify(SERVICE_ID, note);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static void removeNotification(Context ctx) {
		try {
			NotificationManager nm = (NotificationManager) ctx
					.getSystemService(Context.NOTIFICATION_SERVICE);
			//
			nm.cancel(SERVICE_ID);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
